package schoolWork.work05.Example2a;

import javax.swing.*;
import java.awt.*;

public class MyFrm_compute1 extends JFrame {
    JLabel lbl_number = new JLabel("请输入一个数:");
    static JTextField txt_number = new JTextField(10);

    JButton btn_square = new JButton("它的平方是:");
    JButton btn_sqrt = new JButton("它的平方根是:");

    static JTextField txt_square = new JTextField(10);
    static JTextField txt_sqrt = new JTextField(10);

    squareListener listener1 = new squareListener();
    sqrtListener listener2 = new sqrtListener();

    public MyFrm_compute1() {
        setLayout(new GridLayout(3, 3));
        add(lbl_number);
        add(txt_number);
        add(btn_square);
        add(txt_square);
        add(btn_sqrt);
        add(txt_sqrt);

        btn_square.addActionListener(listener1);
        btn_sqrt.addActionListener(listener2);

        setSize(300, 160);
        setVisible(true);
        setTitle("计算");
        setLocationRelativeTo(null);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}

